package dk.pun.dums.client.widget;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import dk.pun.dums.client.view.SelectCharacterView.Presenter;
import dk.pun.dums.shared.character.CharacterData;

public class DeleteCharacterDialog extends DialogBox {

	private static DeleteCharacterDialogUiBinder uiBinder = GWT.create(DeleteCharacterDialogUiBinder.class);

	interface DeleteCharacterDialogUiBinder extends UiBinder<Widget, DeleteCharacterDialog> {}

	@UiField protected transient Label label;
	@UiField protected transient Button okButton;
	@UiField protected transient Button cancelButton;

	private final transient Presenter presenter;
	private final transient CharacterData characterData;
	
	public DeleteCharacterDialog(final Presenter presenter, final CharacterData characterData) {
		super();
		this.setWidget(uiBinder.createAndBindUi(this));
		this.setText("Slet karakter");
		this.setAutoHideEnabled(false);
		this.setGlassEnabled(true);

		this.label.setText("Vil du slette karakteren '" + characterData.getName() + "'?");

		this.presenter = presenter;
		this.characterData = characterData;
	}

	@UiHandler("okButton")
	public void okButtonClicked(final ClickEvent event) {
		this.presenter.onCharacterDeleted(this.characterData);
		this.hide();
	}
	
	@UiHandler("cancelButton")
	public void cancelButtonClicked(final ClickEvent event) {
		this.hide();
	}
	
}
